package com.poetize.plus.entity.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.poetize.plus.entity.po.TimeLine;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Null;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;

/**
 * @author zuosy
 * @created 2024/5/13 14:34
 */
public record TimeLineDTO(
        @Schema(description = "ID")
        @Null(message = "ID必须为空", groups = {Insert.class})
        @NotNull(message = "ID不能为空", groups = {Update.class})
        Long id,

        @Schema(description = "发生时间")
        @NotNull(message = "发生时间不能为空", groups = {Insert.class, Update.class})
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        LocalDateTime occurrenceTime,

        @Schema(description = "内容")
        @NotNull(message = "内容不能为空", groups = {Insert.class, Update.class})
        String content
) {

    public static TimeLine convertDTO(TimeLineDTO timeLineDTO) {
        return new TimeLine(timeLineDTO.id, timeLineDTO.occurrenceTime, timeLineDTO.content);
    }
}
